

_xinstore_db_localstorage = function(){};
_xinstore_db_localstorage.prototype.type = "localStorage";
_xinstore_db_localstorage.prototype.store = null;
_xinstore_db_localstorage.prototype.name = "";

_xinstore_db_localstorage.prototype.test = function(){
    return window.localStorage ? true: false;  
};
_xinstore_db_localstorage.prototype.init = function( name, cfg, onReady ){
    _xinstore_db_localstorage.prototype.store = window.localStorage;
    _xinstore_db_localstorage.prototype.name = name;
    if( typeof(onReady) == "function" ){
        onReady();
    }
};
_xinstore_db_localstorage.prototype._key = function( key ){
    return this.name + "." + key;  
};
_xinstore_db_localstorage.prototype.set = function( key, value ){
    key = this._key( key );
    this.store.setItem( key, value );
};
_xinstore_db_localstorage.prototype.get = function( key ){
    key = this._key( key );
    return this.store.getItem( key );
};
_xinstore_db_localstorage.prototype.remove = function( key ){
    key = this._key( key );
    var value = this.get( key );
    this.store.removeItem( key );
    return value;
};
_xinstore_db_localstorage.prototype.clear = function(){
    var len = this.store.length;
    var i;
    for( i = len; i >= 0; i-- ){
        var key = this.store.key(i);
        if( key.match( "^"+name ) == name ){
            this.store.removeItem( key );
        }
    }
};

xinstore.db.localstorage = new _xinstore_db_localstorage();
xinstore.dbs.push( xinstore.db.localstorage );